package com.cn.demo.service.impl;

import com.cn.demo.entity.Experiment;
import com.cn.demo.mapper.ExperimentMapper;
import com.cn.demo.service.ExperimentService;
import com.cn.demo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ExperimentServiceImpl implements ExperimentService {
    @Autowired
    private ExperimentMapper experimentMapper;

    @Override
    public Result getExperimentSubject(String studentId, String curriculumExperimentId) {
        Experiment experiment =  experimentMapper.getByExperimentIdAndStudentId(curriculumExperimentId,studentId);
        if (experiment!=null){
            return Result.success(experiment);
        }
        return Result.error();
    }

    @Override
    public Result addExperimentSubject(Experiment experiment) {
        if (experimentMapper.insert(experiment)>0){
            return Result.success();
        }
        return Result.error();
    }
}